/**
 * 
 */
package com.wzl.ma;

import com.wzl.ma.db.MaDbAdapter;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

/**
 * @author Wu Wei
 * 
 */
public class CollectUserInfo extends Activity {

	Button btnDone;
	EditText etPassword;
	EditText etMedicalRecord;
	EditText etAllergy;
	EditText etBreakfastTime;
	EditText etLunchTime;
	EditText etDinnerTime;
	CheckBox cbUseESMS;
	EditText etEContactNum;
	EditText etEMessage;
	EditText etDelayThreshold;
	MaDbAdapter dbAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.collectuserinfo);

		dbAdapter = new MaDbAdapter(this);

		btnDone = (Button) findViewById(R.id.btnDone);
		etPassword = (EditText) findViewById(R.id.etPassword);
		etMedicalRecord = (EditText) findViewById(R.id.etMedicalRecord);
		etAllergy = (EditText) findViewById(R.id.etAllergy);
		etBreakfastTime = (EditText) findViewById(R.id.etBreakfastTime);
		etLunchTime = (EditText) findViewById(R.id.etLunchTime);
		etDinnerTime = (EditText) findViewById(R.id.etDinnerTime);
		cbUseESMS = (CheckBox) findViewById(R.id.cbUseESMS);
		etEContactNum = (EditText) findViewById(R.id.etEContactNum);
		etEMessage = (EditText) findViewById(R.id.etEMessage);
		etDelayThreshold = (EditText) findViewById(R.id.etDelayThrshold);

		btnDone.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dbAdapter.open();
				String password = etPassword.getText().toString();
				String medicalrecord = etMedicalRecord.getText().toString();
				String allergy = etAllergy.getText().toString();
				String breakfasttime = etBreakfastTime.getText().toString();
				String lunchtime = etLunchTime.getText().toString();
				String dinnertime = etDinnerTime.getText().toString();
				boolean useesms = cbUseESMS.isChecked();
				String econtactnum = etEContactNum.getText().toString();
				String emessage = etEMessage.getText().toString();
				String delaytheshold = etDelayThreshold.getText().toString();

				ContentValues cv = new ContentValues();
				cv.put("Password", password);
				cv.put("MedicalRecord", medicalrecord);
				cv.put("Allergy", allergy);
				cv.put("BreakfastTime", breakfasttime);
				cv.put("LunchTime", lunchtime);
				cv.put("DinnerTime", dinnertime);
				if (useesms) {
					cv.put("UseESMS", 1);
				} else {
					cv.put("UseESMS", 0);
				}
				cv.put("EContactNum", econtactnum);
				cv.put("EMessage", emessage);
				cv.put("DelayTheshold", delaytheshold);
				
				
				SQLiteDatabase db = dbAdapter.getDatabase();				
				db.insert("UserInformation", null, cv);
				dbAdapter.close();
			}
		});

	}

}
